<?php

class Tutorial extends Connect{
    /*    
    static  $tree;
    static  $drier;
    static  $dragon;
    static  $ingredient;
    static  $boiler;
    static  $mortar;
    static  $podkova;
    static  $buy;
    static  $sell;
    static  $exchange;
    */ 
    
    /**
     
     api_url=http://api.vkontakte.ru/api.php
     api_id=1849660
     api_settings=0
     viewer_id=14921442
     viewer_type=1
     sid=25c01f1a7cde71cb8ff5ffc78d0b6ff1172945b5aea8e24243aa33eca46d4e
     secret=616e4cc215
     user_id=72600916
     group_id=0
     is_app_user=0
     auth_key=276226e057765c06cc86eeb9606e9054
     language=0
     parent_language=0
     domain=vkontakte.ru
     scale=1
     width=750
     height=675
     swf_url=http://cs1497.vkontakte.ru/u505425/62b4aa765099fd.zip
     debug=0     
    */
    
    
    static  $type = array();
    
    function __construct(){
        if(count($type) > 0) return;
        $c = 0;
        /**
         * дракону, дереву, сушилке, ингредиентам, котлу, ступке, часам, торговец, скупщик, обменник
        */
        Tutorial::$type['дракону'] = ++$c; 
        Tutorial::$type['дереву'] = ++$c;
        Tutorial::$type['сушилке'] = ++$c;        
        Tutorial::$type['ингредиентам'] = ++$c;
        Tutorial::$type['котлу'] = ++$c;
        Tutorial::$type['ступке'] = ++$c;
        Tutorial::$type['часам'] = ++$c;
        Tutorial::$type['торговец'] = ++$c;
        Tutorial::$type['скупщик'] = ++$c;
        Tutorial::$type['обменник'] = ++$c;
        Tutorial::$type['гардероб'] = ++$c;
    }        
    
    function getTutorials(){
        $sql = "SELECT * FROM `".PREFIX_STATIC."education` ";
        if(!$result = DBConnect::query($sql, 'tutorials')){
            $this->error(mysql_error());
            return false;
        }
        DBConnect::getAll($result, 'tutorials');
        return DBConnect::$all;     
    }
    
    function saveTutorials( $id, $type, $text ){
        
        $sql = "UPDATE `".PREFIX_STATIC."education` set  `type` = '".$type."', `text` = '".$text."' WHERE `id` = '".$id."' ";
        if(!$result = DBConnect::query($sql)){
            $this->error(mysql_error());
            return false;
        }
        return true;            
        
    }
    
    function newTutorial($type, $text){
        $sql = "INSERT INTO `".PREFIX_STATIC."education` (`type`, `text` ) VALUES ('".$type."', '".$text."') ";
        if(!$result = DBConnect::query($sql)){
            $this->error(mysql_error());
            return false;
        }
        return mysql_insert_id();    
    }
    
    function delTutorial($id){
        $sql = "DELETE FROM `".PREFIX_STATIC."education` WHERE `id` = '".$id."'";
        if(!$result = DBConnect::query($sql)){
            $this->error(mysql_error());
            return false;
        }
        return true;
    } 
    
}

?>